package com.zyh;

/**
 * @Author zyh
 * @Date 2024/8/7 20:35
 * @Description
 */

public class Test {
    public static void main(String[] args) {

        MyTask myTask = new MyTask();
        Thread a = new Thread(myTask, "a");
        a.start();
        Thread b = new Thread(myTask, "b");
        b.start();
    }
}
class MyTask implements Runnable{
    public static final Account ACCOUNT=new Account();
    @Override
    public void run() {
        if (ACCOUNT.getMoney()<3000){
            System.out.println("余额不足");
        }
        else {
            try {
                Thread.sleep(10);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            ACCOUNT.setMoney(ACCOUNT.getMoney()-3000);
            System.out.println(Thread.currentThread().getName()+"取钱成功，还剩下"+ACCOUNT.getMoney());
        }
    }
}
